import { Environment, WindowIsFullscreen } from "@runtime"
import { useDebounce } from "ahooks";
import { useEffect, useState } from "react"

export function DogInTheManger() {
  const [titleInset, setTitleInset] = useState(false)
  const [fullScreen, setFullScreen] = useState(false)
  const debouncedFullScreen = useDebounce(fullScreen, { wait: 500 });
  useEffect(() => {
    titleBarHiddenInset().then((data: boolean) => {
      setTitleInset(data)
    })
    WindowIsFullscreen().then(full => {
      setFullScreen(full)
    })

    const fullHandler = () => {
      WindowIsFullscreen().then(full => {
        setFullScreen(full)
      })
    }

    window.addEventListener('resize', fullHandler)
    return () => {
      window.removeEventListener('resize', fullHandler)
    }

  }, [])

  return <>
    {(titleInset && !debouncedFullScreen) && <button style={{ visibility: 'hidden' }}>占位字符</button>}
  </>
}

const titleBarHiddenInset = (async () => {
  const env = await Environment()
  return env.platform === 'darwin'
})

export default titleBarHiddenInset
